package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.mall.MallPtSetting;
import com.tencreat.service.mall.IMallPtSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author tencreat
 * @date 2021-12-11
 */
@Api(tags="【请填写功能名称】api")
//RestController
@RequestMapping("/mall/setting")
public class MallPtSettingController extends BaseController {
    //@Autowired
    private IMallPtSettingService mallPtSettingService;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation(value="查询【请填写功能名称】列表")
    @PreAuthorize("@ss.hasPermi('mall:setting:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallPtSetting>> list(@RequestBody  MallPtSetting mallPtSetting) {
        QueryWrapper<MallPtSetting> wrapper = Wrappers.query(mallPtSetting);
        Page<MallPtSetting> page =  new Page<>(mallPtSetting.getPageNum(), mallPtSetting.getPageSize());
        return HttpResult.ok(mallPtSettingService.page(page, wrapper));
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation(value="导出【请填写功能名称】列表")
    @PreAuthorize("@ss.hasPermi('mall:setting:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallPtSetting mallPtSetting) {
        List<MallPtSetting> list = mallPtSettingService.selectMallPtSettingList(mallPtSetting);
        ExcelUtil<MallPtSetting> util = new ExcelUtil<MallPtSetting>(MallPtSetting.class);
        return util.exportExcel(list, "setting");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation(value="获取【请填写功能名称】详细信息")
    @PreAuthorize("@ss.hasPermi('mall:setting:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallPtSetting> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallPtSettingService.selectMallPtSettingById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation(value="新增【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('mall:setting:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallPtSetting mallPtSetting) {
        return to(mallPtSettingService.insertMallPtSetting(mallPtSetting));
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation(value="修改【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('mall:setting:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallPtSetting mallPtSetting) {
        return to(mallPtSettingService.updateMallPtSetting(mallPtSetting));
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation(value="删除【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('mall:setting:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallPtSettingService.deleteMallPtSettingByIds(ids));
    }


    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation(value="查询拼团设置列表")
    @PreAuthorize("@ss.hasPermi('mall:setting:mallPtSettinglist')")
    @PostMapping("/mallPtSettinglist")
    public List<MallPtSetting> selectMallPtSettingList(@ApiParam MallPtSetting mallPtSetting) {
        return mallPtSettingService.selectMallPtSettingList(mallPtSetting);
    }

}
